package com.cy.pj.sys.web.controller;

import com.cy.pj.common.util.PageUtil;
import com.cy.pj.log.annotation.RequiredLog;
import com.cy.pj.sys.pojo.SysLog;
import com.cy.pj.sys.server.SysLogService;
import com.cy.pj.sys.web.pojo.JsonResult;
import com.github.pagehelper.ISelect;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.bind.annotation.*;

/**
 * @DATE: 2021/3/15 19:48
 * @Author: LuckyH
 */
@RestController
@RequestMapping("/syslog/")
public class SysLogController {
    @Autowired
    private SysLogService sysLogService;

//    @PostMapping
//    public void doSaveLog(@RequestBody SysLog sysLog){
//        sysLogService.insertLog(sysLog);
//    }

    @RequiredLog(operation = "查询通告")
    @GetMapping
    public JsonResult doSelectLogs(SysLog sysLog){
        //List<SysLog> sysLogs = sysLogService.selectLogs(sysLog);
        PageInfo<SysLog> pageInfo = PageUtil.startPage().doSelectPageInfo(
                new ISelect() {
                    @Override
                    public void doSelect() {
                        sysLogService.selectLogs(sysLog);
                    }
                }
        );
        return new JsonResult(pageInfo);
    }

    @PostMapping
    public JsonResult doInsertLogs(@RequestBody SysLog sysLog){
        sysLogService.insertLog(sysLog);
        return new JsonResult("insert ok");
    }

//    @PutMapping
//    public JsonResult doUpdateLog(){
//
//    }

    @DeleteMapping("{id}")
    public JsonResult doDeleteLogs(@PathVariable Long... id){
        int rows = sysLogService.deleteLogs(id);
        return new JsonResult("delete ok");
    }

    @GetMapping("{id}")
    public JsonResult doSeleteById(@PathVariable Long id){
        SysLog sysLog = sysLogService.selectById(id);
        return new JsonResult(sysLog);
    }
}
